import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useQueryStore = defineStore(
  'query-condition',
  () => {
    const query = ref({
        job: null,
        city: null,
        experience: null,
        salaryBottom: 0,
        salaryTop: 0,
        degrees: null,
        scale: null,
        financing: null,
    })
    const setQuery = (list) => {
        query.value.job = list.job !== undefined? list.job:query.value.job;
        query.value.city = list.city!== undefined?list.city:query.value.city;
        query.value.experience = list.experience!== undefined?list.experience:query.value.experience;
        query.value.salaryBottom = list.salaryBottom!== undefined?list.salaryBottom:query.value.salaryBottom;
        query.value.salaryTop = list.salaryTop!== undefined?list.salaryTop:query.value.salaryTop;
        query.value.degrees = list.degrees!== undefined?list.degrees:query.value.degrees;
        query.value.scale = list.scale!== undefined?list.scale:query.value.scale;
        query.value.financing = list.financing!== undefined?list.financing:query.value.financing;
    }
    const removeQuery = () => {
        query.value.job = null,
        query.value.city = null,
        query.value.experience = null,
        query.value.salaryBottom = 0,
        query.value.salaryTop = 0,
        query.value.degrees = null,
        query.value.scale = null,
        query.value.financing = null
    }
    const jobList = ref([])
    const setjobList = (list) => {
      jobList.value = [];
      jobList.value = list;
    }
    return {
      query,
      setQuery,
      jobList,
      setjobList,
      removeQuery,
    }
  },
  {
    persist: true
  }
)
